/* 
 * AP(r) Computer Science GridWorld Case Study:
 * Copyright(c) 2005-2006 Cay S. Horstmann (http://horstmann.com)
 *
 * This code is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * @author Chris Nevison
 * @author Barbara Cloud Wells
 * @author Cay Horstmann
 */

import info.gridworld.actor.Actor;
import info.gridworld.actor.Critter;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;

import java.awt.*;
import java.util.ArrayList;

/**
 * A <code>CrabCritter</code> looks at a limited set of neighbors when it eats and moves.
 * <br />
 * This class is not tested on the AP CS A and AB exams.
 */
public class QuickCrab extends CrabCritter
{
    public QuickCrab()
    {
        setColor(Color.RED);
    }


    /**
     * @return list of empty locations immediately to the right and to the left for two spaces!
     */
    public ArrayList<Location> getMoveLocations()
    {
        ArrayList<Location> locs = new ArrayList<Location>();
        Grid g = getGrid();
        Location loc = getLocation();
        Location left = loc.getAdjacentLocation(getDirection() + Location.LEFT);
        if (g.isValid(left) && g.get(left)==null) {
            Location twoWayLeft = left.getAdjacentLocation(getDirection() + Location.LEFT);
            if (g.isValid(twoWayLeft) && g.get(twoWayLeft) == null) {
                locs.add(twoWayLeft);
            }
        }
        Location right = loc.getAdjacentLocation(getDirection() + Location.RIGHT);
        if (g.isValid(right) && g.get(right)==null) {
            Location twoWayRight = right.getAdjacentLocation(getDirection() + Location.RIGHT);
            if (g.isValid(twoWayRight) && g.get(twoWayRight) == null) {
                locs.add(twoWayRight);
            }
        }

        return locs;
    }

}
